import myAxios from "@/request";
import type { User, UserQueryRequest, UserUpdateRequest } from "@/models/user";
//data传递参数
export const userRegister = async (data: any) => {
  return await myAxios.post("/api/user/register", data);
};

/**
 * 用户登录
 * @param params
 */
export const userLogin = async (params: any) => {
  return myAxios.request({
    url: "/api/user/login",
    method: "POST",
    data: params,
  });
};

/**
 * 用户注销
 * @param params
 */
export const userLogout = async () => {
  return myAxios.request({
    url: "/api/user/logout",
    method: "post",
  });
};

/**
 * 获取当前用户
 */
export const getCurrentUser = async () => {
  return myAxios.request({
    url: "/api/user/current",
    method: "GET",
  });
};
//获取水电费数据
export const getEquipmentDataVOByUserId = async () => {
  return myAxios.request({
    url: `/api/equipmentData/get/VoByUserId`, // 根据用户 ID 拼接请求 URL
    method: "GET",
  });
};

//获取历史缴费信息

export const listPaymentBillVOByPage = async (params: any) => {
  return myAxios.request({
    url: "/api/paymentBill/list/page/vo",
    method: "POST",
    data: params,
  });
};
/**
 * 获取用户列表
 * @param username
 */
export const searchUsers = async (username: any) => {
  return myAxios.request({
    url: "/api/user/search",
    method: "GET",
    params: {
      username,
    },
  });
};

/**
 * 删除用户
 * @param id
 */
export const deleteUser = async (id: string) => {
  return myAxios.request({
    url: "/api/user/delete",
    method: "POST",
    data: id,
    // 关键点：要传递 JSON 格式的值
    headers: {
      "Content-Type": "application/json",
    },
  });
};
//修改用户
export const updateMyUser = async (data: any) => {
  return await myAxios.post("/api/user/update/my", data, {
    headers: {
      "Content-Type": "application/json",
    },
  });
};

/**
 * 水电费缴费
 * @param money 缴费金额
 * @param equipmentId 设备ID
 */
export const pay = async (money: number, equipmentId: number) => {
  return myAxios.request({
    url: "/api/equipmentData/pay",
    method: "POST",
    params: {
      money,
      equipmentId,
    },
  });
};

/**
 * 获取历史账单
 */
export const getRecentBill = async () => {
  return myAxios.request({
    url: "/api//dormitoryExpenseBill/getRecentBill",
    method: "GET",
  });
};

/**
 * 分页获取用户列表
 */
export function listUserVOByPage(userQueryRequest: UserQueryRequest) {
  return myAxios.request({
    url: "/api/user/list/page/vo",
    method: "post",
    data: userQueryRequest,
  });
}
export function listUserByPage(userQueryRequest: UserQueryRequest) {
  return myAxios.request({
    url: "/api/user/list/page",
    method: "post",
    data: userQueryRequest,
  });
}

// 添加更新用户信息的 API
export function updateUser(userUpdateRequest: UserUpdateRequest) {
  return myAxios.request({
    url: "/api/user/update",
    method: "post",
    data: userUpdateRequest,
  });
}
